/**
 * Created by yangxianming on 2018/7/18.
 * 添加动作需要完成下列步骤:
 * 1. 增加actionName数组中的动作名称
 * 2. 添加动作需要增加 getActionData : 用户在保存动作时获取动作相关参数
 * 3. 添加动作需要增加 selectAction  : 用户在选择动作后加载动作描述，比如xpath content等
 * 4. 添加动作需要增加 editActions   : 获取用例数据后加载动作描述数据
 *
 */

//var projects;

var actionName = [
    ["browser", "browserName"],
    ["page", "url"],
    ["click", "webElement"],
    ["sendKeys", "webElement", "content"],
    ["catchData", "webElement", "howCatch", "reflectName"],
    ["caseQuote"],
    ["switchFrame"],
    ["sqlWord"],
    ["saveSession"],
    ["waitUntilFind"],
    ["login"],
    ["javaScript"],
    ["listClick", "webElement", "tarText"],
    ["waitTime"]
];
var actions = [""];

var switchTo = ["son","default"];
var browserName = ["ie", "chrome", "firefox"];
var webElement = ["xpath", "id", "classname"];
var howCatch = ["getText", "getAttribute", "getAttributeCount", "getSize", "getList", "getWindowsCount"];
var loginMethod = ["manual", "automatic"];

var analysisType = [
    ["comparison", "==", "!=", "<", ">", "<=", ">="],
    ["noNull", "==", "!="],
    ["contain", "->", "<->"],
    ["Double", "==", "!=", "<", ">", "<=", ">="],
    ["Date", "==", "!=", "<", ">", "<=", ">="]
];
var analysisTypes = [""];

//获取项目列表, 需要加载主页项目列表，新增项目弹框中的项目列表
function apiGetProject(dofun, dofun_2){
    var data = {
        "action":"getProject"
    };

    var xmlHttp1 = new XMLHttpRequest();
    xmlHttp1.onreadystatechange = function(){
        if (xmlHttp1.readyState==4){
            if(xmlHttp1.status==200){
                var r = JSON.parse(xmlHttp1.response);
                if (r["apiStatus"] == "0") {
                    alert(r["errorMsg"])
                }
                if (r["apiStatus"] == "1"){
                    dofun(r["result"]);
                    dofun_2(r["result"]);
                }
            }
        }
    };
    xmlHttp1.open("POST", "/configuration/projectManager", true);
    xmlHttp1.send(JSON.stringify(data));
}
function loadProjectData(){
    apiGetProject(drawLoadProjectList, drawTopDivProject);
}
//加载主页面项目列表,
function drawLoadProjectList(data){
    var project = document.getElementById("projects");
    var allData = ["全部项目"];
    for(var i = 0; i < data.length; i++){
        allData.push(data[i]);
    }
    loadSelectList(project, allData);
    project.onchange = function(){loadCases()};
    //这里同时加载case列表
    loadCases();
}
//加载添加用例悬浮层的项目列表
function drawTopDivProject(data){
    loadSelectList(document.getElementById("projectName"), data);
}
//动态加载下拉菜单
function loadSelectList(selectObject, jsonData){
    selectObject.options.length = 0;
    for (var index = 0; index < jsonData.length; index++){
        selectObject.options.add(new Option(jsonData[index], index))
    }
}

function initializeData(){
    loadProjectData();
    projects = window.globalConfig.projects;
    for(var i = 0; i < actionName.length; i++){
        actions.push(actionName[i][0]);
    }
    for(var x = 0; x < analysisType.length; x++){

        analysisTypes.push(analysisType[x][0]);
    }
    //loadSelectList(document.getElementById("projects"), projects);
    //loadSelectList(document.getElementById("projectName"), projects.splice(1, projects.length));
    //loadCases();
    document.getElementById("projects").onchange = function(){loadCases()};
}

function highLight(node){
    //高亮显示本行
    if(document.getElementById("highLight") != null){
        document.getElementById("highLight").style.backgroundColor = "";
        document.getElementById("highLight").removeAttribute("id");
    }
    node.setAttribute("id", "highLight");
    node.style.backgroundColor = "#ffeaea";
}

function loadCases(){
    //加载用例
    var tbody = document.getElementById("caseList").getElementsByTagName("tbody")[0];
    //清空所有行,保留抬头
    var firstTr = tbody.getElementsByTagName("tr")[0];
    tbody.innerText = "";
    tbody.appendChild(firstTr);

    //var testCases = [
    //    ["开放平台", "验证标题", "验证标题是否符合预期", "0"],
    //    ["开放平台", "验证排序", "验证列表排序是否正确", "1"]
    //];
    var saveData = {"type":"2"};
    //获取项目名
    var selectValue = selectedText(document.getElementById("projects"));
    if (selectValue != "全部项目"){
        saveData.projectName = selectValue;
    }
    //获取关键字
    var words = document.getElementById("words").value.trim();
    if (words != ""){
        saveData.caseName = words;
    }
    var testCases = [];
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "/caseManager/queryCase", true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    testCases = r["result"];

                    for(var i = 0; i < testCases.length; i++){
                        var tr = document.createElement("tr");
                        tr.onclick = function(){highLight(this)};
                        for(var one = 0; one < testCases[i].length; one++){
                            var td = document.createElement("td");
                            if(one == 0){
                                tr.setAttribute("caseid", testCases[i][one]);
                                continue;
                            }
                            if(one == 4){
                                //设置操作按钮
                                var span = document.createElement("span");
                                var span2 = document.createElement("span");
                                var span3 = document.createElement("span");
                                var span4 = document.createElement("span");
                                span.setAttribute("class", "forTwoWord");
                                span2.setAttribute("class", "forTwoWord");
                                span3.setAttribute("class", "forTwoWord");
                                span4.setAttribute("class", "forTwoWord");
                                span.innerText = "编辑";
                                span.onclick = function(){editActions(this.parentNode.parentNode);};
                                span2.innerText = "删除";
                                span2.onclick = function(){deleteCase(this.parentNode.parentNode.getAttribute("caseid"));};
                                span3.innerText = "运行";
                                span3.onclick = function(){runCase(this.parentNode.parentNode.getAttribute("caseid"), "");};
                                span4.innerText = "复制";
                                span4.onclick = function(){copyCase(this.parentNode.parentNode.getAttribute("caseid"));};
                                td.appendChild(span);
                                td.appendChild(span2);
                                td.appendChild(span3);
                                td.appendChild(span4);
                                tr.appendChild(td);
                                continue;
                            }
                            if(one == 5){
                                tr.setAttribute("ipAddress", testCases[i][one]);
                                continue;
                            }
                            td.innerText = testCases[i][one];
                            td.style.cursor = "pointer";
                            td.onclick = function(){controlTopDivUT('open', '编辑用例', this.parentNode)};
                            tr.appendChild(td);
                        }
                        tbody.appendChild(tr);
                    }
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };

    xmlHttp.send(JSON.stringify(saveData));
}

function copyCase(caseId){
    if(!confirm("确认复制嘛？")){
        return;
    }

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/caseManager/copyCase?caseId=" + caseId, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    var caseActions = document.getElementById("caseActions").getElementsByTagName("tbody")[0];
                    var caseActionHeader = caseActions.getElementsByTagName("tr")[0];
                    caseActions.innerText = "";
                    caseActions.append(caseActionHeader);
                    loadCases();
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

//页面的用例全部执行
function runAll(){
    var l = document.getElementById("caseList").getElementsByTagName("tbody")[0].getElementsByTagName("tr");
    var p = "";
    var le = l.length;
    for (var i = 0; i < le; i++){
        if(l[i].getAttribute("caseid")){
            p = p + l[i].getAttribute("caseid");
            if (i < (le - 1)){
                p = p + ",";
            }
        }
    }
    var ipForTitle = document.getElementById("ipForTitle").value.trim();
    runCase(p, ipForTitle)
}

//单个执行
function runCase(caseId, ipForTitle){
    if(!confirm("开始跑测试喽？")){
        return;
    }
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/caseManager/runCase?caseId=" + caseId + "&ipForTitle=" + ipForTitle, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    //loadCases();
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

function deleteCase(caseId){

    if(!confirm("确认删除嘛？")){
        return;
    }
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/caseManager/delCase?caseId=" + caseId, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    loadCases();
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

function loadAnalysisSign(analysisTypeName, tr){
    var select = tr.getElementsByTagName("select")[1];
    select.innerText = "";
    for(var i = 0; i < analysisType.length; i++){
        if(analysisType[i][0] == analysisTypeName){
            for(var x = 1; x < analysisType[i].length; x++){
                select.options.add(new Option(analysisType[i][x], x));
            }
            break;
        }
    }
}

function editActions(node){
    //获取caseid
    var caseid = node.getAttribute("caseid");
    //高亮显示本行
    //if(document.getElementById("highLight") != null){
    //    document.getElementById("highLight").style.backgroundColor = "";
    //    document.getElementById("highLight").removeAttribute("id");
    //}
    //node.setAttribute("id", "highLight");
    //node.style.backgroundColor = "#ffeaea";

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/caseManager/getCaseData?caseid=" + caseid, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    addActions(node);
                    if(typeof(r["result"]) == "undefined"){
                        return;
                    }
                    for(var i = 0; i < r["result"].length; i++){
                        var trIndex = i + 1;
                        addAction();
                        var tbody = document.getElementById("caseActions").getElementsByTagName("tbody")[0];
                        var lastActionTR = tbody.getElementsByTagName("tr")[trIndex];
                        var oneActionData = r["result"][i];
                        //加载“是否跳过”数据
                        if(oneActionData["isJump"] == 1){
                            lastActionTR.getElementsByTagName("td")[0].getElementsByTagName("input")[0].checked = true;
                        }
                        //加载"异常跳过"数据
                        if(oneActionData["isException"] == 1){
                            lastActionTR.getElementsByTagName("td")[1].getElementsByTagName("input")[0].checked = true;
                        }
                        //加载“动作名称”数据  oneActionData["actionName"]
                        var selectActionName = lastActionTR.getElementsByTagName("td")[2].getElementsByTagName("select")[0];
                        for(var s = 0; s < selectActionName.options.length; s++){
                            if(selectActionName.options[s].innerText == oneActionData["actionName"]){
                                selectActionName.options[s].selected = true;
                                selectAction(selectActionName, selectActionName.parentNode.parentNode);
                                break;
                            }
                        }
                        //加载“动作描述” td3是“动作描述”
                        var td3 = lastActionTR.getElementsByTagName("td")[3];
                        //td3divX 每个动作描述中一行一个td3divX
                        var td3div0,td3div1,td3div2,td3div3,td3div4,td3div5,td3div6,td3div7;
                        if(oneActionData["actionName"] == "browser"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["borwser"]);
                        }
                        if(oneActionData["actionName"] == "page"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["page"];
                        }
                        if(oneActionData["actionName"] == "click"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];
                        }
                        if(oneActionData["actionName"] == "sendKeys"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];

                            td3div1 = td3.getElementsByTagName("div")[1];
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["content"];
                        }
                        if(oneActionData["actionName"] == "catchData"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];

                            td3div1 = td3.getElementsByTagName("div")[1];
                            setSelectChecked(td3div1.getElementsByTagName("select")[0], oneActionData["actionDes"]["howToGet"]);
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["attributeName"];

                            td3div2 = td3.getElementsByTagName("div")[2];
                            td3div2.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["reflectName"];

                            //预期值
                            var td4 = lastActionTR.getElementsByTagName("td")[4];
                            setSelectChecked(td4.getElementsByTagName("select")[0], oneActionData["actionDes"]["expect"]["type"]);
                            loadAnalysisSign(oneActionData["actionDes"]["expect"]["type"], td4);
                            td4.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["expect"]["left"];
                            setSelectChecked(td4.getElementsByTagName("select")[1], oneActionData["actionDes"]["expect"]["sign"]);
                            td4.getElementsByTagName("input")[1].value = oneActionData["actionDes"]["expect"]["right"];
                        }
                        if(oneActionData["actionName"] == "caseQuote"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["caseQuote"];
                        }
                        if(oneActionData["actionName"] == "switchFrame"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["switchTo"]);

                            td3div1 = td3.getElementsByTagName("div")[1];
                            setSelectChecked(td3div1.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];
                        }
                        if(oneActionData["actionName"] == "sqlWord"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["sqlWord"];
                        }
                        if(oneActionData["actionName"] == "saveSession"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["sessionMark"];
                        }
                        if(oneActionData["actionName"] == "waitUntilFind"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];

                            td3div1 = td3.getElementsByTagName("div")[1];
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["targetText"];
                        }
                        if(oneActionData["actionName"] == "login"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["loginUrl"];

                            td3div1 = td3.getElementsByTagName("div")[1];
                            setSelectChecked(td3div1.getElementsByTagName("select")[0], oneActionData["actionDes"]["userNameElementType"]);
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["userNameElementDes"];

                            td3div2 = td3.getElementsByTagName("div")[2];
                            td3div2.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["userName"];

                            td3div3 = td3.getElementsByTagName("div")[3];
                            setSelectChecked(td3div3.getElementsByTagName("select")[0], oneActionData["actionDes"]["passWordElementType"]);
                            td3div3.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["passWordElementDes"];

                            td3div4 = td3.getElementsByTagName("div")[4];
                            td3div4.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["passWord"];

                            td3div5 = td3.getElementsByTagName("div")[5];
                            setSelectChecked(td3div5.getElementsByTagName("select")[0], oneActionData["actionDes"]["loginMethod"]);

                            td3div6 = td3.getElementsByTagName("div")[6];
                            setSelectChecked(td3div6.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div6.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];

                            td3div7 = td3.getElementsByTagName("div")[7];
                            setSelectChecked(td3div7.getElementsByTagName("select")[0], oneActionData["actionDes"]["loginSuccessElementType"]);
                            td3div7.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["loginSuccessElementDes"];
                        }
                        if(oneActionData["actionName"] == "javaScript"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["js"];
                        }
                        if(oneActionData["actionName"] == "listClick"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            setSelectChecked(td3div0.getElementsByTagName("select")[0], oneActionData["actionDes"]["elementType"]);
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["elementDes"];

                            td3div1 = td3.getElementsByTagName("div")[1];
                            td3div1.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["tarText"];
                        }
                        if(oneActionData["actionName"] == "waitTime"){
                            td3div0 = td3.getElementsByTagName("div")[0];
                            td3div0.getElementsByTagName("input")[0].value = oneActionData["actionDes"]["waitTime"];
                        }
                        //加载“文字描述”
                        lastActionTR.getElementsByTagName("td")[5].getElementsByTagName("input")[0].value = oneActionData["textDescription"];
                    }
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

function addActions(node){
    //清空右侧动作列表，准备添加用例步骤
    var caseActions = document.getElementById("caseActions");
    var tbody = caseActions.getElementsByTagName("tbody")[0];
    //清空所有行,保留抬头
    var firstTr = tbody.getElementsByTagName("tr")[0];
    tbody.innerText = "";
    tbody.appendChild(firstTr);

    caseActions.setAttribute("caseid", node.getAttribute("caseid"));

    var td = document.createElement("td");
    var tr = document.createElement("tr");
    tr.setAttribute("t", "tail");
    td.setAttribute("style", "text-align:center;cursor:pointer;");
    td.setAttribute("colspan", "7");
    td.onclick = function(){addAction()};
    td.innerText = "+";
    tr.appendChild(td);
    tbody.appendChild(tr);

    var td1 = document.createElement("td");
    var tr1 = document.createElement("tr");
    tr1.setAttribute("t", "tail");
    td1.setAttribute("style", "text-align:center;cursor:pointer;");
    td1.setAttribute("colspan", "7");
    td1.onclick = function(){saveAction()};
    td1.innerText = "save";
    tr1.appendChild(td1);
    tbody.appendChild(tr1);
}

function saveAction(){
    //调试
    getActionData();
}

function getActionData(){
    //获取用例数据 并提交保存
    var caseActions = document.getElementById("caseActions").getElementsByTagName("tbody")[0];
    var tr = caseActions.getElementsByTagName("tr");

    var caseid = document.getElementById("caseActions").getAttribute("caseid");
    //var action = {"caseid":caseid};
    var actionArr = [];
    for(var i = 0; i < tr.length; i++){
        if(!tr[i].hasAttribute("t")){
            var trData = {};
            var expect = {};
            var TDs = tr[i].getElementsByTagName("td");

            //通过动作名称的数据,如果没有选动作就不加入数组，也就不保存
            var select1 = TDs[2].getElementsByTagName("select")[0];
            if(select1.selectedIndex == 0){
                continue;
            }
            //不显示的也不保存
            if(tr[i].getAttribute("style") == "display: none;"){
                continue;
            }

            //是否跳过
            var input1 = TDs[0].getElementsByTagName("input")[0];
            if(input1.checked){
                trData["isJump"] = "1";
            }else{
                trData["isJump"] = "0";
            }

            //异常是否跳过
            var input2 = TDs[1].getElementsByTagName("input")[0];
            if(input2.checked){
                trData["isException"] = "1";
            }else{
                trData["isException"] = "0";
            }

            //动作名称
            trData["actionName"] = selectedText(select1);

            //动作描述
            var tds3 = TDs[3].getElementsByTagName("div")[0];
            if(select1.selectedIndex == 1){
                //browser
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    trData["actionDes"] = {"borwser":selectedText(div_select)};
                })();
            }
            if(select1.selectedIndex == 2){
                //page
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {"page":div_input.value};
                })();
            }
            if(select1.selectedIndex == 3){
                //click
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "elementType":selectedText(div_select),
                        "elementDes":div_input.value
                    };
                })();
            }
            if(select1.selectedIndex == 4){
                //sendKeys
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    var div_input2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "elementType":selectedText(div_select),
                        "elementDes":div_input.value,
                        "content":div_input2.value
                    };
                })();
            }
            if(select1.selectedIndex == 5){
                //catchData
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    var div_select2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("select")[0];
                    var div_input2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];
                    var div_input3 = TDs[3].getElementsByTagName("div")[2].getElementsByTagName("input")[0];
                    //预期字段  {"type":"Contain","left":"${message}","sign":"->","right":"发送成功"}
                    var ex_select1,ex_input1,ex_select2,ex_input2;
                    ex_select1 = TDs[4].getElementsByTagName("select")[0];
                    ex_input1 = TDs[4].getElementsByTagName("input")[0];
                    ex_select2 = TDs[4].getElementsByTagName("select")[1];
                    ex_input2 = TDs[4].getElementsByTagName("input")[1];
                    expect = {
                        "type":selectedText(ex_select1),
                        "left":ex_input1.value,
                        "sign":selectedText(ex_select2),
                        "right":ex_input2.value
                    };
                    trData["actionDes"] = {
                        "elementType":selectedText(div_select),
                        "elementDes":div_input.value,
                        "howToGet":selectedText(div_select2),
                        "attributeName":div_input2.value,
                        "reflectName":div_input3.value,
                        "expect":expect
                    };
                })();
            }
            if(select1.selectedIndex == 6){
                //caseQuote
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {"caseQuote":div_input.value};
                })();
            }
            if(select1.selectedIndex == 7){
                //switchFrame
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_select2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("select")[0];
                    var div_input2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "switchTo":selectedText(div_select),
                        "elementType":selectedText(div_select2),
                        "elementDes":div_input2.value};
                })();
            }
            if(select1.selectedIndex == 8){
                //sqlWord
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {"sqlWord":div_input.value};
                })();
            }
            if(select1.selectedIndex == 9){
                //saveSession
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {"sessionMark":div_input.value};
                })();
            }
            if(select1.selectedIndex == 10){
                //waitUntilFind
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    var div_input2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "elementType":selectedText(div_select),
                        "elementDes":div_input.value,
                        "targetText":div_input2.value
                    };
                })();
            }
            if(select1.selectedIndex == 11){
                //login
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];

                    var div_select3 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("select")[0];
                    var div_input5 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];

                    var div_input2 = TDs[3].getElementsByTagName("div")[2].getElementsByTagName("input")[0];

                    var div_select4 = TDs[3].getElementsByTagName("div")[3].getElementsByTagName("select")[0];
                    var div_input6 = TDs[3].getElementsByTagName("div")[3].getElementsByTagName("input")[0];

                    var div_input3 = TDs[3].getElementsByTagName("div")[4].getElementsByTagName("input")[0];

                    var div_select = TDs[3].getElementsByTagName("div")[5].getElementsByTagName("select")[0];

                    var div_select2 = TDs[3].getElementsByTagName("div")[6].getElementsByTagName("select")[0];
                    var div_input4 = TDs[3].getElementsByTagName("div")[6].getElementsByTagName("input")[0];

                    var div_select5 = TDs[3].getElementsByTagName("div")[7].getElementsByTagName("select")[0];
                    var div_input7 = TDs[3].getElementsByTagName("div")[7].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "loginUrl":div_input.value,
                        "userNameElementType":selectedText(div_select3),
                        "userNameElementDes":div_input5.value,
                        "userName":div_input2.value,
                        "passWordElementType":selectedText(div_select4),
                        "passWordElementDes":div_input6.value,
                        "passWord":div_input3.value,
                        "loginMethod":selectedText(div_select),
                        "elementType":selectedText(div_select2),
                        "elementDes":div_input4.value.replace(/"/g, "'"),
                        "loginSuccessElementType":selectedText(div_select5),
                        "loginSuccessElementDes":div_input7.value
                    };
                })();
            }
            if(select1.selectedIndex == 12){
                //javaScript
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "js":div_input.value
                    };
                })();
            }
            if(select1.selectedIndex == 13){
                //listClick
                (function (){
                    var div_select = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("select")[0];
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    var div_input2 = TDs[3].getElementsByTagName("div")[1].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "elementType":selectedText(div_select),
                        "elementDes":div_input.value,
                        "tarText":div_input2.value
                    };
                })();
            }
            if(select1.selectedIndex == 14){
                (function (){
                    var div_input = TDs[3].getElementsByTagName("div")[0].getElementsByTagName("input")[0];
                    trData["actionDes"] = {
                        "waitTime":div_input.value
                    };
                })();
            }

            //文字描述
            trData["textDescription"] = TDs[5].getElementsByTagName("input")[0].value;

            actionArr.push(trData);
        }
    }

    //action["actionArr"] = actionArr;
    //console.log(JSON.stringify(action));

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "/caseManager/updateCaseData?caseid=" + caseid, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    alert("保存成功");
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send(JSON.stringify(actionArr));
}

function addAction(){
    var caseActions = document.getElementById("caseActions").getElementsByTagName("tbody")[0];
    var tableLength = caseActions.getElementsByTagName("tr").length-2;
    var tr = caseActions.insertRow(tableLength);

    //是否跳过
    var td1 = document.createElement("td");
    var input1 = document.createElement("input");
    input1.setAttribute("class", "checkboxForTD");
    input1.type = "checkbox";
    input1.title = "选中就跳过";
    td1.appendChild(input1);
    tr.appendChild(td1);

    //是否异常
    var td2 = document.createElement("td");
    var input2 = document.createElement("input");
    input2.setAttribute("class", "checkboxForTD");
    input2.type = "checkbox";
    input2.title = "选中就跳过";
    td2.appendChild(input2);
    tr.appendChild(td2);

    //动作名称  class="forTD" onchange="selectAction(this, this.parentNode.parentNode)
    var td3 = document.createElement("td");
    var select1 = document.createElement("select");
    select1.setAttribute("class", "forTD");
    select1.onchange = function(){selectAction(this, this.parentNode.parentNode)};
    loadSelectList(select1, actions);
    td3.appendChild(select1);
    tr.appendChild(td3);

    //动作描述
    var td4 = document.createElement("td");
    tr.appendChild(td4);

    //预期
    var td5 = document.createElement("td");
    var select2 = document.createElement("select");
    var input3 = document.createElement("input");
    var select3 = document.createElement("select");
    var input4 = document.createElement("input");
    select2.setAttribute("class", "forTD");
    select2.style.width = "40%";
    select2.onchange = function(){loadAnalysisSign(select2[select2.selectedIndex].text, this.parentNode)};
    loadSelectList(select2, analysisTypes);
    input3.type = "text";
    input3.placeholder = "left";
    input3.setAttribute("class", "forTD");
    input3.style.width = "22.5%";
    select3.setAttribute("class", "forTD");
    select3.style.width = "15%";
    input4.type = "text";
    input4.placeholder = "right";
    input4.setAttribute("class", "forTD");
    input4.style.width = "22.5%";
    td5.appendChild(select2);
    td5.appendChild(input3);
    td5.appendChild(select3);
    td5.appendChild(input4);
    tr.appendChild(td5);

    //文字描述
    var td6 = document.createElement("td");
    var input5 = document.createElement("input");
    input5.type = "text";
    input5.placeholder = "步骤描述";
    input5.setAttribute("class", "forTD");
    input5.style.width = "100%";
    td6.appendChild(input5);
    tr.appendChild(td6);

    //操作
    var td7 = document.createElement("td");
    var span1 = document.createElement("span");
    var span2 = document.createElement("span");
    //var span3 = document.createElement("span");
    var span4 = document.createElement("span");
    span1.setAttribute("class", "forTD");
    span1.innerText = "上";
    span1.onclick = function(){moveUp(this)};
    span2.setAttribute("class", "forTD");
    span2.innerText = "下";
    span2.onclick = function(){moveDown(this)};
    //span3.setAttribute("class", "forTD");
    //span3.innerText = "增";
    span4.setAttribute("class", "forTD");
    span4.innerText = "删";
    span4.onclick = function(){this.parentNode.parentNode.style.display = "none"};
    td7.appendChild(span1);
    td7.appendChild(span2);
    //td7.appendChild(span3);
    td7.appendChild(span4);
    tr.appendChild(td7);
}


function moveUp(_a){
    var _row = _a.parentNode.parentNode;
    //如果不是第一行，则与上一行交换顺序
    var _node = _row.previousSibling;
    //while(_node && _node.nodeType != 1){
    //    _node = _node.previousSibling;
    //}
    if(_node.getAttribute("t") != "header"){
        swapNode(_row,_node);
    }
}
function moveDown(_a){
    var _row = _a.parentNode.parentNode;
    //如果不是最后一行，则与下一行交换顺序
    var _node = _row.nextSibling;
    //while(_node && _node.nodeType != 1){
    //    _node = _node.nextSibling;
    //}
    if(_node.getAttribute("t") != "tail"){
        swapNode(_row,_node);
    }
}
function swapNode(node1,node2){
    //获取父结点
    var _parent = node1.parentNode;
    //获取两个结点的相对位置
    var _t1 = node1.nextSibling;
    var _t2 = node2.nextSibling;
    //将node2插入到原来node1的位置
    if(_t1)_parent.insertBefore(node2,_t1);
    else _parent.appendChild(node2);
    //将node1插入到原来node2的位置
    if(_t2)_parent.insertBefore(node1,_t2);
    else _parent.appendChild(node1);
}

//输入"动作名称"，并创建"动作描述"
function selectAction(obj, tr){
    var text = selectedText(obj);
    var td = tr.getElementsByTagName("td")[3];
    td.innerText = "";

    if(text == "browser"){
        (function (){
            var select = document.createElement("select");
            var div = document.createElement("div");
            div.style.width = "100%";

            select.setAttribute("class", "forTD");
            loadSelectList(select, browserName);
            div.appendChild(select);
            td.appendChild(div);
        })();
    }
    if(text == "page"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";

            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "input url";
            div.appendChild(input);
            td.appendChild(div);
        })();
    }
    if(text == "click"){
        (function (){
            var select = document.createElement("select");
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";

            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "input web element";
            div.appendChild(select);
            div.appendChild(input);
            td.appendChild(div);
        })();

    }
    if(text == "catchData"){
        (function (){
            var select = document.createElement("select");
            var select2 = document.createElement("select");
            var input = document.createElement("input");
            var input2 = document.createElement("input");
            var input3 = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            var div2 = document.createElement("div");
            div2.style.width = "100%";
            var div3 = document.createElement("div");
            div3.style.width = "100%";

            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "input web element";
            div.appendChild(select);
            div.appendChild(input);
            td.appendChild(div);

            select2.setAttribute("class", "forTD");
            select2.style.width = "30%";
            loadSelectList(select2, howCatch);
            input2.type = "text";
            input2.setAttribute("class", "forTD");
            input2.style.width = "70%";
            input2.placeholder = "attribute Name";
            div2.appendChild(select2);
            div2.appendChild(input2);
            td.appendChild(div2);

            input3.type = "text";
            input3.setAttribute("class", "forTD");
            input3.style.width = "100%";
            input3.placeholder = "reflect name";
            div3.appendChild(input3);
            td.appendChild(div3);
        })();

    }
    if(text == "sendKeys"){
        (function (){
            var select = document.createElement("select");
            var input = document.createElement("input");
            var input2 = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            var div2 = document.createElement("div");
            div2.style.width = "100%";

            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "input web element";
            div.appendChild(select);
            div.appendChild(input);
            td.appendChild(div);

            input2.type = "text";
            input2.setAttribute("class", "forTD");
            input2.style.width = "100%";
            input2.placeholder = "content";
            div2.appendChild(input2);
            td.appendChild(div2);
        })();
    }
    if(text == "caseQuote"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";

            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "输入需要引用的用例名称或者用例id";
            div.appendChild(input);
            td.appendChild(div);
        })();
    }
    if(text == "switchFrame"){
        (function (){
            var select = document.createElement("select");
            var select2 = document.createElement("select");
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            var div2 = document.createElement("div");
            div2.style.width = "100%";

            select.setAttribute("class", "forTD");
            loadSelectList(select, switchTo);
            div.appendChild(select);
            td.appendChild(div);

            select2.setAttribute("class", "forTD");
            select2.style.width = "30%";
            loadSelectList(select2, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "input web element";
            div2.appendChild(select2);
            div2.appendChild(input);
            td.appendChild(div2);
        })();

    }
    if(text == "sqlWord"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";

            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "input sqlWord";
            div.appendChild(input);
            td.appendChild(div);
        })();

    }
    if(text == "saveSession"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";

            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "input mark, letter only";
            div.appendChild(input);
            td.appendChild(div);
        })();
    }
    if(text == "waitUntilFind"){
        (function (){
            var select = document.createElement("select");
            var input = document.createElement("input");
            var input2 = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            var div2 = document.createElement("div");
            div2.style.width = "100%";

            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "wait until find web element";
            div.appendChild(select);
            div.appendChild(input);
            td.appendChild(div);

            input2.type = "text";
            input2.setAttribute("class", "forTD");
            input2.style.width = "100%";
            input2.placeholder = "wait until find web element's Text";
            div2.appendChild(input2);
            td.appendChild(div2);
        })();
    }
    if(text == "login"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "input login-page url";
            div.appendChild(input);
            td.appendChild(div);

            var select = document.createElement("select");
            var input2 = document.createElement("input");
            var div2 = document.createElement("div");
            div2.style.width = "100%";
            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input2.type = "text";
            input2.setAttribute("class", "forTD");
            input2.style.width = "70%";
            input2.placeholder = "input username element";
            div2.appendChild(select);
            div2.appendChild(input2);
            td.appendChild(div2);

            var input3 = document.createElement("input");
            var div3 = document.createElement("div");
            div3.style.width = "100%";
            input3.type = "text";
            input3.setAttribute("class", "forTD");
            input3.placeholder = "input username";
            div3.appendChild(input3);
            td.appendChild(div3);

            var select2 = document.createElement("select");
            var input4 = document.createElement("input");
            var div4 = document.createElement("div");
            div4.style.width = "100%";
            select2.setAttribute("class", "forTD");
            select2.style.width = "30%";
            loadSelectList(select2, webElement);
            input4.type = "text";
            input4.setAttribute("class", "forTD");
            input4.style.width = "70%";
            input4.placeholder = "input password element";
            div4.appendChild(select2);
            div4.appendChild(input4);
            td.appendChild(div4);

            var input5 = document.createElement("input");
            var div5 = document.createElement("div");
            div5.style.width = "100%";
            input5.type = "text";
            input5.setAttribute("class", "forTD");
            input5.placeholder = "input password";
            div5.appendChild(input5);
            td.appendChild(div5);

            var select3 = document.createElement("select");
            var div6 = document.createElement("div");
            div6.style.width = "100%";
            select3.setAttribute("class", "forTD");
            select3.style.width = "30%";
            loadSelectList(select3, loginMethod);
            div6.appendChild(select3);
            td.appendChild(div6);

            var select4 = document.createElement("select");
            var input6 = document.createElement("input");
            var div7 = document.createElement("div");
            div7.style.width = "100%";
            select4.setAttribute("class", "forTD");
            select4.style.width = "30%";
            loadSelectList(select4, webElement);
            input6.type = "text";
            input6.setAttribute("class", "forTD");
            input6.style.width = "70%";
            input6.placeholder = "input login button element";
            div7.appendChild(select4);
            div7.appendChild(input6);
            td.appendChild(div7);

            var select5 = document.createElement("select");
            var input7 = document.createElement("input");
            var div8 = document.createElement("div");
            div8.style.width = "100%";
            select5.setAttribute("class", "forTD");
            select5.style.width = "30%";
            loadSelectList(select5, webElement);
            input7.type = "text";
            input7.setAttribute("class", "forTD");
            input7.style.width = "70%";
            input7.placeholder = "location after manual login";
            div8.appendChild(select5);
            div8.appendChild(input7);
            td.appendChild(div8);
        })();
    }
    if(text == "javaScript"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "input js script";
            div.appendChild(input);
            td.appendChild(div);
        })();
    }
    if(text == "listClick"){
        (function (){
            var select = document.createElement("select");
            var input = document.createElement("input");
            var input2 = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            var div2 = document.createElement("div");
            div2.style.width = "100%";

            select.setAttribute("class", "forTD");
            select.style.width = "30%";
            loadSelectList(select, webElement);
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.style.width = "70%";
            input.placeholder = "input web element,no last index!no last index!";
            div.appendChild(select);
            div.appendChild(input);
            td.appendChild(div);

            input2.type = "text";
            input2.setAttribute("class", "forTD");
            input2.style.width = "100%";
            input2.placeholder = "target text";
            div2.appendChild(input2);
            td.appendChild(div2);
        })();
    }
    if(text == "waitTime"){
        (function (){
            var input = document.createElement("input");
            var div = document.createElement("div");
            div.style.width = "100%";
            input.type = "text";
            input.setAttribute("class", "forTD");
            input.placeholder = "wait time, only long type value, default and error are 1 ";
            div.appendChild(input);
            td.appendChild(div);
        })();
    }
}

function controlTopDivUT(mySwitch, text, trObject){
    var topDiv = document.getElementById('createCase');
    if (mySwitch == "open") {
        //设置页面抬头
        document.getElementById('topDivTitle').innerText = text;

        //显示页面
        //topDiv.style.marginTop = document.documentElement.scrollTop + "px";
        topDiv.style.display = "block";
    }
    //创建和编辑功能判断
    if (trObject != undefined){
        //编辑
        var td = trObject.getElementsByTagName("td");
        var projectSelect = document.getElementById("projectName");
        document.getElementById("caseId").setAttribute("caseId", trObject.getAttribute("caseid"));
        for (var i = 0; i < projectSelect.options.length; i++) {
            if (projectSelect.options[i].text == td[0].innerText) {
                projectSelect.options[i].selected = true;
                break;
            }
        }
        document.getElementById("caseName").value = td[1].innerText;
        document.getElementById("describe").value = td[2].innerText;
        document.getElementById("ipAddress").value = trObject.getAttribute("ipAddress");
        document.getElementById("saveButton").onclick = function(){updateCase()};
    }else{
        //添加
        document.getElementById("projectName").options[0].selected = true;
        document.getElementById("caseName").value = "";
        document.getElementById("describe").value = "";
        document.getElementById("saveButton").onclick = function(){saveCase()};
    }
    if (mySwitch == "close") topDiv.style.display = "none";
}

function updateCase(){
    //{"projectName":"开放平台","caseName":"用例名字xx","describe":"描述xx","id":"1"}
    var data = {
        "projectName": selectedText(document.getElementById("projectName")),
        "caseName": document.getElementById("caseName").value.trim(),
        "describe": document.getElementById("describe").value.trim(),
        "id": document.getElementById("caseId").getAttribute("caseid"),
        "ipAddress": document.getElementById("ipAddress").value.trim()
    };

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "/caseManager/updateCase", true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    controlTopDivUT('close', '');
                    loadCases(); //刷新列表
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send(JSON.stringify(data));
}

function saveCase(){
    var projectName = selectedText(document.getElementById("projectName"));
    var caseName = document.getElementById("caseName").value.trim();
    var describe = document.getElementById("describe").value.trim();
    var ipAddress = document.getElementById("ipAddress").value.trim();

    var saveData = {
        "projectName": projectName,
        "caseName": caseName,
        "describe": describe,
        "ip": ipAddress,
        "data":"",
        "type": "2",
        "isdel": "0"
    };

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "/caseManager/addCase", true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    controlTopDivUT('close', '');
                    loadCases(); //刷新列表
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send(JSON.stringify(saveData));
}